#include <stdio.h>

void sum_rows(int va[3][4], int vb);
void sum_cols(int va[3][4], int vb);
int sum2d(int va[3][4], int vb);

int main()
{
  /*4005fc:	a9bc7bfd 	stp	x29, x30, [sp, #-64]!
  400600:	910003fd 	mov	x29, sp
  400604:	90000000 	adrp	x0, 400000 <_init-0x480>
  400608:	9123e001 	add	x1, x0, #0x8f8	// init value, Need debugging to know
  40060c:	910043a0 	add	x0, x29, #0x10	// a
  400610:	a9400c22 	ldp	x2, x3, [x1]
  400614:	a9000c02 	stp	x2, x3, [x0]		// 16/4=4
  400618:	a9410c22 	ldp	x2, x3, [x1, #16]
  40061c:	a9010c02 	stp	x2, x3, [x0, #16]	// 4
  400620:	a9420821 	ldp	x1, x2, [x1, #32]
  400624:	a9020801 	stp	x1, x2, [x0, #32]*/	// 4
	int a[3][4] = {
		{2, 4, 6, 8}, {3, 5, 7, 9},{12, 10, 8, 6} 
	};

  /*400628:	910043a0 	add	x0, x29, #0x10
  40062c:	52800061 	mov	w1, #0x3                   	// #3
  400630:	9400000e 	bl	400668 <sum_rows>*/
	sum_rows(a, 3);

  /*400634:	910043a0 	add	x0, x29, #0x10
  400638:	52800061 	mov	w1, #0x3                   	// #3
  40063c:	94000032 	bl	400704 <sum_cols>*/
	sum_cols(a, 3);

  /*400640:	910043a0 	add	x0, x29, #0x10
  400644:	52800061 	mov	w1, #0x3                   	// #3
  400648:	94000056 	bl	4007a0 <sum2d>
  /40064c:	2a0003e1 	mov	w1, w0
  400650:	90000000 	adrp	x0, 400000 <_init-0x480>
  400654:	91236000 	add	x0, x0, #0x8d8
  400658:	97ffffa6 	bl	4004f0 <printf@plt>*/
	printf("%d\n", sum2d(a, 3));

  /*40065c:	52800000 	mov	w0, #0x0                   	// #0
  400660:	a8c47bfd 	ldp	x29, x30, [sp], #64
  400664:	d65f03c0 	ret*/
	return 0;
}

void sum_rows(int va[3][4], int vb)
{
  /*400668:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  40066c:	910003fd 	mov	x29, sp
  400670:	f9000fa0 	str	x0, [x29, #24]	// [x29+24]=va
  400674:	b90017a1 	str	w1, [x29, #20]	// [x29+20]=vb
  400678:	b9002fbf 	str	wzr, [x29, #44]*/
	int a = 0;

  /*40067c:	1400001b 	b	4006e8 <sum_rows+0x80>*/
  
  /*400680:	b90027bf 	str	wzr, [x29, #36]
  400684:	b9002bbf 	str	wzr, [x29, #40]*/
	int b = 0;
	int c = 0;

  /*400688:	1400000d 	b	4006bc <sum_rows+0x54>
  40068c:	b9802fa0 	ldrsw	x0, [x29, #44]	// x0=a, 从[x29, #44]处加载4个字节，并符号扩展进X0
  400690:	d37cec00 	lsl	x0, x0, #4			// x0=a<<4
  400694:	f9400fa1 	ldr	x1, [x29, #24]		// x1=va
  400698:	8b000020 	add	x0, x1, x0			// x0=va+(a<<4)
  40069c:	b9802ba1 	ldrsw	x1, [x29, #40]	// x1=c
  4006a0:	b8617800 	ldr	w0, [x0, x1, lsl #2]	// w0=(va+(a<<4))+(c<<2)
  4006a4:	b94027a1 	ldr	w1, [x29, #36]		// w1 = b
  4006a8:	0b000020 	add	w0, w1, w0			// w0 = b+(va+(a<<4))+(c<<2)
  4006ac:	b90027a0 	str	w0, [x29, #36]		// b=w0
  4006b0:	b9402ba0 	ldr	w0, [x29, #40]		// w0=c
  4006b4:	11000400 	add	w0, w0, #0x1		// w0=c+1
  4006b8:	b9002ba0 	str	w0, [x29, #40]		// [x29+40]=c+1
  4006bc:	b9402ba0 	ldr	w0, [x29, #40]		// w0=c
  4006c0:	71000c1f 	cmp	w0, #0x3
  4006c4:	54fffe4d 	b.le	40068c <sum_rows+0x24>	// le:有符号数小于或等于

  4006c8:	90000000 	adrp	x0, 400000 <_init-0x480>
  4006cc:	9124a000 	add	x0, x0, #0x928
  4006d0:	b94027a2 	ldr	w2, [x29, #36]	// w2=b
  4006d4:	b9402fa1 	ldr	w1, [x29, #44]	// w1=a
  4006d8:	97ffff86 	bl	4004f0 <printf@plt>

  4006dc:	b9402fa0 	ldr	w0, [x29, #44]	// w0=a
  4006e0:	11000400 	add	w0, w0, #0x1	// w0=a+1
  4006e4:	b9002fa0 	str	w0, [x29, #44]	// [x29+44]=a
  4006e8:	b9402fa1 	ldr	w1, [x29, #44]	// w1=a
  4006ec:	b94017a0 	ldr	w0, [x29, #20]	// w0=vb
  4006f0:	6b00003f 	cmp	w1, w0
  4006f4:	54fffc6b 	b.lt	400680 <sum_rows+0x18>  // b.tstop	lt:有符号数小于
  4006f8:	d503201f 	nop*/
	for (a = 0; a < vb; a++) {
		b = 0;
		for (c = 0; c <= 3; c++) {
			b += va[a][c];
		}	// - - -

		printf("%d %d\n", a, b);
	}

  /*4006fc:	a8c37bfd 	ldp	x29, x30, [sp], #48
  400700:	d65f03c0 	ret*/
}

void sum_cols(int va[3][4], int vb)
{
  /*400704:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  400708:	910003fd 	mov	x29, sp
  40070c:	f9000fa0 	str	x0, [x29, #24]	// va
  400710:	b90017a1 	str	w1, [x29, #20]	// vb
  400714:	b9002bbf 	str	wzr, [x29, #40]*/
	int a = 0;

  /*400718:	1400001c 	b	400788 <sum_cols+0x84>*/

  /*40071c:	b90027bf 	str	wzr, [x29, #36]
  400720:	b9002fbf 	str	wzr, [x29, #44]*/
	int b = 0, c = 0;

  /*400724:	1400000d 	b	400758 <sum_cols+0x54>
  400728:	b9802fa0 	ldrsw	x0, [x29, #44]	// x0=c, 从[x29, #44]处加载4个字节，并符号扩展进X0
  40072c:	d37cec00 	lsl	x0, x0, #4			// x0=c<<4
  400730:	f9400fa1 	ldr	x1, [x29, #24]		// x1=va
  400734:	8b000020 	add	x0, x1, x0			// x0=va+(c<<4)
  400738:	b9802ba1 	ldrsw	x1, [x29, #40]	// x1=a
  40073c:	b8617800 	ldr	w0, [x0, x1, lsl #2]	// w0=(va+(c<<4))+(a<<2)
  400740:	b94027a1 	ldr	w1, [x29, #36]		// w1 = b
  400744:	0b000020 	add	w0, w1, w0			// w0 = b+(va+(c<<4))+(a<<2)
  400748:	b90027a0 	str	w0, [x29, #36]		// b=w0
  40074c:	b9402fa0 	ldr	w0, [x29, #44]		// w0=c
  400750:	11000400 	add	w0, w0, #0x1		// w0=c+1
  400754:	b9002fa0 	str	w0, [x29, #44]		// [x29+44]=c
  400758:	b9402fa1 	ldr	w1, [x29, #44]		// w1=c
  40075c:	b94017a0 	ldr	w0, [x29, #20]		// w0=vb
  400760:	6b00003f 	cmp	w1, w0
  400764:	54fffe2b 	b.lt	400728 <sum_cols+0x24>  // b.tstop	lt:有符号数小于

  400768:	90000000 	adrp	x0, 400000 <_init-0x480>
  40076c:	91250000 	add	x0, x0, #0x940
  400770:	b94027a2 	ldr	w2, [x29, #36]		// b
  400774:	b9402ba1 	ldr	w1, [x29, #40]		// a
  400778:	97ffff5e 	bl	4004f0 <printf@plt>

  40077c:	b9402ba0 	ldr	w0, [x29, #40]		// a
  400780:	11000400 	add	w0, w0, #0x1		// a+1
  400784:	b9002ba0 	str	w0, [x29, #40]		// [x29+40]=a
  400788:	b9402ba0 	ldr	w0, [x29, #40]		// w0=a
  40078c:	71000c1f 	cmp	w0, #0x3
  400790:	54fffc6d 	b.le	40071c <sum_cols+0x18>	le:有符号数小于或等于
  400794:	d503201f 	nop*/
	for (a = 0; a <=3 ; a++) {
		b = 0;
		for (c = 0; c < 3; c++) {
			b += va[c][a];
		}	// | | | |

		printf("%d %d\n", a, b);
	}
  /*400798:	a8c37bfd 	ldp	x29, x30, [sp], #48
  40079c:	d65f03c0 	ret*/
}

int sum2d(int va[3][4], int vb)
{
  /*4007a0:	d10083ff 	sub	sp, sp, #0x20
  4007a4:	f90007e0 	str	x0, [sp, #8]	// va
  4007a8:	b90007e1 	str	w1, [sp, #4]	// vb
  4007ac:	b90017ff 	str	wzr, [sp, #20]
  4007b0:	b9001fff 	str	wzr, [sp, #28]*/
	int a = 0, b = 0;

  /*4007b4:	14000015 	b	400808 <sum2d+0x68>*/

  /*4007b8:	b9001bff 	str	wzr, [sp, #24]*/
	int c = 0;

  /*4007bc:	1400000d 	b	4007f0 <sum2d+0x50>*/

  /*4007c0:	b9801fe0 	ldrsw	x0, [sp, #28]	// x0=b, 从[sp+28]处加载4个字节，并符号扩展进X0
  4007c4:	d37cec00 	lsl	x0, x0, #4			// x0=b<<4
  4007c8:	f94007e1 	ldr	x1, [sp, #8]		// x1=va
  4007cc:	8b000020 	add	x0, x1, x0			// x0=va+(b<<4)
  4007d0:	b9801be1 	ldrsw	x1, [sp, #24]	// x1=c
  4007d4:	b8617800 	ldr	w0, [x0, x1, lsl #2]	// w0=(va+(b<<4))+(c<<2)
  4007d8:	b94017e1 	ldr	w1, [sp, #20]		// w1=a
  4007dc:	0b000020 	add	w0, w1, w0			// w0=a+(va+(b<<4))+(c<<2)
  4007e0:	b90017e0 	str	w0, [sp, #20]		// a=w0
  4007e4:	b9401be0 	ldr	w0, [sp, #24]		// w0=c
  4007e8:	11000400 	add	w0, w0, #0x1		// c+1
  4007ec:	b9001be0 	str	w0, [sp, #24]		
  4007f0:	b9401be0 	ldr	w0, [sp, #24]		// w0=c
  4007f4:	71000c1f 	cmp	w0, #0x3
  4007f8:	54fffe4d 	b.le	4007c0 <sum2d+0x20>*/

  /*4007fc:	b9401fe0 	ldr	w0, [sp, #28]		// w0=b
  400800:	11000400 	add	w0, w0, #0x1		// b+1
  400804:	b9001fe0 	str	w0, [sp, #28]
  400808:	b9401fe1 	ldr	w1, [sp, #28]		// w1=b
  40080c:	b94007e0 	ldr	w0, [sp, #4]		// w0=vb
  400810:	6b00003f 	cmp	w1, w0
  400814:	54fffd2b 	b.lt	4007b8 <sum2d+0x18>*/  // b.tstop
	for (b = 0; b < vb; b++) {
		for (c = 0; c <= 3; c++) {
			a += va[b][c];
		}
	}

  /*400818:	b94017e0 	ldr	w0, [sp, #20]	// w0=a
  40081c:	910083ff 	add	sp, sp, #0x20
  400820:	d65f03c0 	ret
  400824:	00000000 	.inst	0x00000000 ; undefined*/
	return a;
}
